package com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.bean.QueryBean;

import java.util.List;

import demo.zdc.com.myapplication.R;

/**
 * Created by mhysa on 2017/1/20.
 */
public class QueryAdapter extends BaseAdapter {


    Context context;
    List<QueryBean.ExhibitionListBean> list;
    private final LayoutInflater inflater;

    public QueryAdapter(Context context,List<QueryBean.ExhibitionListBean> list){

        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null) {
            viewHolder = new ViewHolder();
            convertView =  inflater.inflate(R.layout.spnner_item,parent, false);
            viewHolder.textview = (TextView) convertView.findViewById(R.id.tv_spinner);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.textview.setText(list.get(position).getExhibition());
        return convertView;
    }

    public class ViewHolder{
        private TextView textview;
    }
}
